package com.company;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Arrange {
    List allList = new ArrayList();;
    //递归实现全排列
    public List arrange(List str, String prefix, int length) {
        if (prefix.length() == length) {
            String[] s = new String[] { prefix.substring(0, 1),
                    prefix.substring(1, 2), prefix.substring(2, 3),
                    prefix.substring(3, 4), prefix.substring(4) };//截取字符串
            allList.add(s);//得到一种排列就添加
        }
        for (int i = 0; i < str.size(); i++) {
            List temp = new LinkedList(str);
            arrange(temp, prefix + temp.remove(i), length);
        }
        return allList;
    }
}
